<template>
	<view class="back-view" @touchmove.stop.prevent="moveHandle">
		<view class="view-background"></view>
		<view class="white-view-back">
			<view class="top-back">
				<view class="top-name">移除参与用户</view>
				<view class="close-back" @click="closeBtnAction">
					<image class="close-img" src="../../../static/close.png"></image>
				</view>
			</view>
			<view class="top-line"></view>
			<view class="content-back">
				<view class="item-back" v-for="(item,index) in customerList">
					<image class="header-img" :src="item.user.account.avatarPic"></image>
					<view class="header-name">{{item.user.account.realName}}</view>
					<view class="del-back" @click="delAction(index)">
						<image class="image-del" src="../../../static/cancel.png"></image>
					</view>
				</view>
			</view>
			<view class="bottom-back">
				<view class="bottom-btn bottom-btn-cancel" @click="closeBtnAction">取消</view>
				<view class="bottom-btn" @click="saveAction">确认</view>
			</view>
		</view>
	</view>
</template>

<script>
	let app = ''
	
	export default {
		props: {
			selectItemID: {
				type: String,
				default: ''
			},
		},
		data() {
			return {
				role: '', //当前登录角色
				roleUrl: '',
				customerList: []
			}
		},
		mounted() {
			var _this = this;
			app = getApp()
			_this.role = app.globalData.role
			_this.roleUrl = _this.$roleUrl({
				tab: _this.role
			})
			this.getCaseUserCustomers();
		},
		methods: {
			/**
			 * 参与用户
			 */
			async getCaseUserCustomers() {
				let _this = this
				const res = await _this.$myRequest({
					url: `/${_this.roleUrl}/caseUser/users`,
					data: {
						caseId: _this.selectItemID,
					}
				})
				// console.log('参与用户',res)
				if (res.data.code == 200) {
					_this.customerList = res.data.data	
				}
			},
			async saveAction() {		
				let _this = this
				
				var arr = [];
				for (var i = 0; i < this.customerList.length; i++) {
					var item = this.customerList[i];
					
					arr.push(item.userId)
				}
				var parms = {
					'caseId': _this.selectItemID,
					'userIds': arr,
				}
				console.log(parms)
				
				var url = "/admin/caseUser/users/1";
				const res = await this.$myRequest({
					url: url,
					method: 'POST',
					data: parms
				})
				console.log('返回结果', res)
			
				if (res.data.code == 200) {
					uni.showToast({
						title: '移除成功'
					})
					_this.$emit("successBack");
					_this.closeBtnAction()
				}
			},
			
			closeBtnAction() {
				console.log('222')
				this.$emit('clickCustomerListDelClose')
			},
			moveHandle() {
				return true
			},
			delAction(index) {
				this.customerList.splice(index, 1)
			}

		},
	}
</script>

<style>
	.back-view {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		z-index: 199;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.view-background {
		position: absolute;
		width: 100%;
		height: 100%;
		z-index: 100;
		background-color: rgba(0, 0, 0, 0.3);
	}

	.white-view-back {
		width: 556px;
		height: 500px;
		padding: 24px;
		max-height: 540px;
		background-color: white;
		margin-top: -50px;
		border-radius: 4px;
		z-index: 101;
		position: absolute;
	}

	.top-back {
		display: flex;
		justify-content: space-between;
	}

	.top-name {
		font-size: 18px;
		font-weight: normal;
		color: #333333;

	}

	.close-back {
		cursor: pointer;
		width: 20px;
		height: 20px;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.close-img {
		width: 12px;
		height: 12px;
	}

	.top-line {
		height: 1px;
		background: #EEEEEE;
		width: 100%;
		margin-top: 20px;
		margin-bottom: 20px;
	}

	.content-back {
		display: flex;
		flex-wrap: wrap;
	}

	.item-back {
		margin: 18px;
		display: flex;
		justify-content: center;

		align-items: center;
		flex-direction: column;
		position: relative;
	}

	.header-img {
		height: 56px;
		width: 56px;
		border-radius: 50%;
		background-color: #EEEEEE;
	}

	.header-name {
		font-size: 14px;
		font-weight: 600;
		color: #333333;
		margin-top: 6px;
	}

	.image-del {
		background-color: white;

		border-radius: 50%;
		width: 14px;
		height: 14px;
		margin-left: 5px;
	}

	.del-back {
		position: absolute;
		right: 0px;
		top: 0px;
		width: 20px;
		height: 20px;

	}
	.bottom-back {
	
		bottom: 0px;
		width: 100%;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		position: absolute;
		height: 60px;
		right: 16px;
	}
	
	.bottom-btn {
		cursor: pointer;
		width: 104px;
		height: 32px;
		background: #2DA9C5;
		border-radius: 2px;
		color: #FFFFFF;
		font-size: 14px;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	
	.bottom-btn-cancel {
		margin-right: 10px;
		background: #FFFFFF;
		border: 1px solid #EEEEEE;
		color: #333333;
	}
	
</style>
